<%-- 
    Document   : cart_user
    Created on : 23.04.2013, 0:15:08
    Author     : Yasya, Kate
--%>


<%@page import="entity.Product"%>
<%@page import="delta.cart.bean.CartLocal"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%! CartLocal cart;%>
<% cart = (CartLocal) session.getAttribute("cart");
    session.setAttribute("pageNumber", null);
    session.setAttribute("sortBy", null);
%>


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/cart.css">
        <link rel="stylesheet" type="text/css" href="css/all.css">
        <script type="text/javascript" src="scripts/quantityValidator.js"></script>
        <title>Cart</title>
    </head>
    <body>      
        <header>
            <div id ="top_name">
                  <a href="main.jsp"> <img src="/Delta-war/product/1.jpeg"></a>
                  <h1> Cart</h1> </div>
        </header>
        <div id="main">
            <center>
                <font color="red">   
                <span 
                    id="error">
                    <%=request.getParameter("error")!=null ? request.getParameter("error") : ""  %>

                </span>
                </font>
            </center>

            <div id="basket">
                <table>

                    <%for (Product product : cart.getProductList().keySet()) {%>
                    <TR>
                        <td id="first" ><%=product.getName()%></td>
                        <td id="second">
                            <form
                                id="quantity_form"
                                action="ProductRecalc"
                                >
                                <input 
                                    name="id_product"
                                    value="<%=product.getId_product()%>"
                                    type="hidden"
                                    >
                                <input 
                                    id="quantity_<%=product.getId_product()%>"
                                    name="quantity" 
                                    type="number"
                                    value="<%=cart.getProductList().get(product)%>"
                                    min="1" 
                                    onchange="if (validateFields()) submit()"/>
                            </form>

                        </td>

                        <td 
                            id="third"> 
                            <span 
                                id="price_<%=product.getId_product()%>">
                                <%=cart.getProductList().get(product) * product.getPrice()%>
                            </span>
                        </td>

                        <td 
                            id="third"> 
                            <form 

                                method="Post" 
                                action="RemoveFromCart">
                                <input 
                                    name="id_product"
                                    value="<%=product.getId_product()%>"
                                    type="hidden"
                                    />
                                <button  

                                    type="submit" >
                                    Delete 
                                </button> 
                            </form> 
                        </td>
                    </TR>
                    <%}%>


                </table>
            </div>
            <div id="total">

                <p> Total price:  
                    &nbsp &nbsp  
                    <input 
                        id="total_price"
                        type="text" 
                        name="Customer_name" 
                        value="<%=cart.getTotalPrice()%>"
                        size="10" 

                        readonly/>
                </p>  

            </div>


            <form 
                method="Post" 
                action="main.jsp">
                <button 
                    id="func" 
                    type="submit" >
                    Back to shop
                </button> 
            </form> 

            <form 
                id="confirm_form"
                method="Post" 
                action="order_user.jsp">

                <input
                    id="confirm" 
                    type="button" 
                    value="Confirm"
                    onclick="if (validateFields()) submit()"
                    <%if (cart.getCount() == 0) {%>
                    disabled<%}%>

                    />
            </form>
        </div>
                    <div id="footer">
                                <p>  &#169;All rights reserved</p>
                            </div>
    </body>
</html>
